#include<stdio.h>
#include<stdlib.h>
#include<time.h>

void menu()
{
    printf("*********************\n");
    printf("***1. paly 0. exit***\n");
    printf("*********************\n");
}

void game()
{
    int input = 0;
    printf("请猜数字:->"); 
    //生成随机数范围1~100
    int num = rand()%100+1;
    //判断数字大小
    while (input != num)
    {
        scanf("%d", &input);
        if(input > num)
        {
            printf("猜大了\n");
            printf("请重新输入:->");
        }
        else if(input < num)
        {
            printf("猜小了\n");
            printf("请重新输入:->");
        }
        else
        {
            printf("猜对了\n");
        }
    }
}

//猜数字游戏
int main(){
    int input = 0;
    srand((unsigned int)time(NULL));
    do
    {
        menu();
        printf("请输入数字:->");
        scanf("%d", &input);
        
        switch (input)
        {
        case 1:
            game();
            break;
        case 0:
            printf("退出游戏\n");
            break;
        default:
            printf("输入错误，请重新输入:->\n");
            break;
        }
    } while (input);
    
    return 0;
}